import { Component, OnInit } from '@angular/core';
import {NzNotificationService} from "ng-zorro-antd/notification";
import {FileUploadService} from "@core/service/FileUploadService";
import {NzModalService} from "ng-zorro-antd/modal";
import {UploadFileTask} from "@shared/models/UploadFileTask";
import {TestData} from "@shared/utils/TestData";
import {OfflineTask} from "@shared/models/OfflineTask";

@Component({
  selector: 'bby-upload',
  templateUrl: './upload.component.html',
  styleUrls: ['./upload.component.scss']
})
export class UploadComponent implements OnInit {
  checkedFiles:any;
  constructor(private msg : NzNotificationService,
              private dialogService:NzModalService,
              public uploadService : FileUploadService,
  ) {
    // this.taskList=fileUploadService.taskList;
  }

  ngOnInit(): void {

  }

  delTaskClick(task: UploadFileTask, id: number) {
    let that = this;
    let nzContent;
    if (task.status=='success'){
      nzContent="文件"+task.name+"已经上传完成，此操作将删除已上传的文件，是否继续？"
    }else {
      nzContent="确认取消上传文件'"+task.name+"'?"
    }
    that.dialogService.create({
      nzTitle:"删除任务",
      nzWidth:'400px',nzCentered:true,
      nzContent:nzContent,
      nzOnOk:($event: Event) => {
        if (task.canceler) {
          task.canceler.unsubscribe()
        }
        that.uploadService.delTask(id);
      },
    })
  }

  startOfflineClick(task: OfflineTask) {

  }

  delOfflineClick(task: OfflineTask, id: number) {
    if (task.status!='success'){
      this.dialogService.confirm({
        nzTitle:'取消任务',
        nzContent:'此任务下载还未完成，确定要删除？',
        nzOnOk:()=>{
          this.uploadService.delOfflineTask(task,id)
        }
      })
    }else{
      this.uploadService.delOfflineTask(task,id)
    }
  }
}
